package com.shop.shopserver.controller.user;

import com.shop.shopcommon.result.Result;
import com.shop.shoppojo.entity.Category;
import com.shop.shoppojo.vo.CategoryVO;
import com.shop.shopserver.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/category")
@RequiredArgsConstructor
@Slf4j
@Api(tags = "商品模块")
public class CategoryController {
    /**
     * 商品分类
     */

    @Autowired
    private CategoryService categoryService;

    @GetMapping("/getCategoryData")
    @ApiOperation(value = "商品全部分类")
    public Result<Map<String, List<CategoryVO>>> getCategoryTree(){
        log.info("到缓存中找");
        List<CategoryVO> categoryTree = categoryService.getData();
        Map<String,List<CategoryVO>> map = new HashMap<>();
        map.put("list", categoryTree);
        return Result.success(map, "获取商品分类成功");

    }


}
